from bs4 import BeautifulSoup
import requests
headers={
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0"
}       #任意网站右键点开“检查”，再点击“网络”（“network”），随便点开一个请求查看标头（headers）下的User-Agent内容复制过来
        #从而状态码从418变为200
response=requests.get("https://movie.douban.com/top250",headers=headers)
print(response.status_code)

#print(response.text)

#只能获取1-25的电影
# html=response.text
# soup=BeautifulSoup(html,"html.parser")
# all_titles=soup.findAll("span",attrs={"class":"title"})
# for title in all_titles:
#     title_string=title.string
#     if "/" not in title_string:
#         print(title_string)

for start_num in range(0,250,25):
    response=requests.get(f"https://movie.douban.com/top250?start={start_num}&filter=",headers=headers)
    html=response.text
    soup=BeautifulSoup(html,"html.parser")
    all_titles=soup.findAll("span",attrs={"class":"title"})
    for title in all_titles:
        title_string=title.string
        if "/" not in title_string:
            print(title_string)
